home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / tbl_func.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  3KB  |  91 lines

  1. /*****************************************************************************
  2.   FILE           : tbl_func.c
  3.   SHORTNAME      : 
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS-Kernel: Transfer functions using table lookup and
  7.                linear approximation method
  8.   NOTES          :
  9.  
  10.   AUTHOR         : Niels Mache
  11.   DATE           : 25.07.91
  12.  
  13.   CHANGED BY     : Sven Doering
  14.   IDENTIFICATION : @(#)tbl_func.c    1.8 3/15/94
  15.   SCCS VERSION   : 1.8
  16.   LAST CHANGE    : 3/15/94
  17.  
  18.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  19.  
  20. ******************************************************************************/
  21. #include <stdio.h>
  22. #include <math.h>
  23.  
  24. #include "kr_typ.h"        /*    Kernel types and constants  */
  25. #include "kr_const.h"       /*  Constant Declarators for SNNS-Kernel  */
  26. #include "func_mac.h"        /*    Transfer function macros  */
  27. #include "tbl_func.ph"
  28.  
  29.  
  30. /*#################################################
  31.  
  32. GROUP: Unit activation functions using table lookup
  33.        and linear approximation method
  34.  
  35. #################################################*/
  36.  
  37.  
  38. /*  Sigmoid function
  39.     using table lookup and linear approximation method
  40. */
  41. FlintType   ACT_LogisticTbl(struct Unit *unit_ptr)
  42. {
  43. #include "sigmoid.tbl"    /*  m,b value tables for linear approximation  */
  44.  
  45.   ACT_FUNC_DEFS
  46.   register FlintType  sum, x;
  47.   register int    index;
  48.  
  49.  
  50.   sum =  0.0;
  51.   if (GET_FIRST_SITE( unit_ptr ))
  52.     do
  53.       sum += GET_SITE_VALUE;
  54.     while (GET_NEXT_SITE);
  55.   else
  56.     if (GET_FIRST_UNIT_LINK( unit_ptr ))
  57.       do
  58.         sum += GET_WEIGHTED_OUTPUT;
  59.       while (GET_NEXT_LINK);
  60.  
  61. /*  ***************************************************  */
  62.  
  63.  
  64.   x = sum + GET_UNIT_BIAS( unit_ptr );
  65.   index = (int) (x * SCALE_FACTOR) + INDEX_OFFSET;
  66.  
  67.   if (index < 0)
  68.     {  /*  x is less then MIN_APPROX_X:
  69.        approx. func value to MINUS_INFINITE_FUNC_VALUE  */
  70.     if (index <= MIN_INDEX)
  71.       { /*  printf( "x below -infinite : %g\n", x );  */
  72.     return( MINUS_INFINITE_FUNC_VALUE );
  73.       }
  74.     /*    printf( "x below MIN_APPROX_X : %g\n", x );  */
  75.     return( m[0] * x + b[0] );
  76.     }
  77.  
  78.   if (index > NO_OF_APPROX)
  79.     {  /*  x is greater then MAX_APPROX_X:
  80.        approx. func value to PLUS_INFINITE_FUNC_VALUE  */
  81.     if (index >= MAX_INDEX)
  82.       { /*  printf( "x above +infinite : %g\n", x );  */
  83.     return( PLUS_INFINITE_FUNC_VALUE );
  84.       }
  85.     /*    printf( "x above MAX_APPROX_X : %g\n", x );  */
  86.     return( m[ NO_OF_APPROX ] * x + b[ NO_OF_APPROX ] );
  87.     }
  88.  
  89.   return( m[ index ] * x + b[ index ] );
  90. }
  91.